package com.example.routes

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import java.io.File

fun Route.fileRoutes() {
    get("cover/{img}") {
        val img = call.parameters["img"]
        val type = call.parameters["type"]
        val file = if (type != null) File("src/main/resources/image/240/${img}") else File("src/main/resources/image/${img}")
        if (file.exists()) {
            call.respondFile(file)
        } else {
            call.respond(HttpStatusCode.NotFound)
        }
    }
}